home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 May / Macworld (1998-05).dmg / Shareware World / Info / Apple Wizards March 1998 / Apple Wizards 1998 - March / Apple Wizards 1998 - March.rsrc / TEXT_138.txt < prev    next >
Text File  |  1998-02-27  |  9KB  |  274 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15. Welcome to HTML ToolBox. This month we will begin looking at tables and their uses. Tables can be found in nearly every well-designed website on the Internet. For example, check out both http://www.microsoft.com/ and http://www.apple.com/ . Both pages are excellent examples of how tables can be used to create the perfect layout for a website.
  16.  
  17.  
  18.  
  19.  
  20. HTML Tables
  21.  
  22. The first time I came in contact with tables was when I looked at the HTML source for http://www.shareware.com/ . I was intrigued by the "toolbar" which appeared at the left edge of the page. What really grabbed my attention was the fact that the page did not use frames to separate the links in the toolbar from the contents of the page. I quickly chose to view the source for the page, and what I found was an HTML tag that would change the face of web page design for me. The tag was <TABLE>.
  23.  
  24.  
  25.  
  26.  
  27. Tables, Tables, Everywhere!
  28.  
  29. The average computer user comes in contact with tables every day of his or her life. Take, for instance, the Finder. When you set a window to list its contents by name, you get something that looks like this:
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. One row of the table represents one "item." Each column of the table represents a property of the items in the table. In the file listing above, the rows represent a file, and the columns hold the name, modification date, size, and label associated with each file.
  46.  
  47. Since we've seen the Finder's file listing as an example of the application of tables, we will attempt to create an HTML table which mirrors the general appearance and function of the Finder file list.
  48.  
  49.  
  50.  
  51.  
  52. Defining the Table
  53.  
  54. <TABLE [CELLPADDING="num" CELLSPACING="num" WIDTH="num" HEIGHT="num" BORDER="num" BGCOLOR="color"]>
  55.   :
  56. </TABLE>
  57.  
  58. The TABLE tag defines the general structure of your table. The properties you specify within the TABLE tag apply to the entire table, unless the property is overridden by an individual row or cell.  Thus, defining a table using the HTML code
  59.  
  60. <TABLE BORDER="1">
  61.     <TR>
  62.         <TD>
  63.             Text
  64.         </TD>
  65.         <TD>
  66.             in
  67.         </TD>
  68.         <TD>
  69.             Table
  70.         </TD>
  71.     </TR>
  72.     <TR>
  73.         <TD>
  74.             Format
  75.         </TD>
  76.     </TR>
  77. </TABLE>
  78.  
  79. produces a table which looks like this:
  80.  
  81.  
  82.  
  83.  
  84.  
  85. The browser sizes the table horizontally to the width of the widest row and vertically to the height of the highest column. We'll get to the <TR> and <TD> tags momentarily. You've already seen the use of the BORDER parameter in the <TABLE> specification; a list of the most commonly used parameters in the <TABLE> specification follows. By default, the table is transparent so that the page background ‚Äî be it a picture or a solid color ‚Äî shows through.
  86.  
  87. CELLPADDING  Pads the inside of cells with num pixels on each side.
  88. CELLSPACING  Pads the outside of cells with num pixels on each side.
  89. WIDTH        Force the table to a static width of num pixels.
  90. HEIGHT                            Force the table to a static height of num pixels.
  91. BORDER       Each cell has a stylized border placed around it.  The thickness
  92.              of the border is equal to num pixels.
  93. BGCOLOR                        Each cell within the table defaults to color as its background
  94.                       color.
  95.  
  96. Once you've defined the general format for the table, you're ready to begin adding the individual table cells.
  97.  
  98.  
  99.  
  100.  
  101. Adding a Row
  102.  
  103. <TR [VALIGN="TOP|MIDDLE|BOTTOM" ALIGN=LEFT|CENTER|RIGHT BGCOLOR="color"]>
  104.   :
  105. </TR>
  106.  
  107. Between the table definition and the end of the table (</TABLE>) you add row definitions using the TR tag.  All objects are by default vertically centered and the row is as wide as the table.
  108.  
  109. VALIGN       Force the objects to be aligned vertically to the top, middle, or
  110.              bottom of the row.  Default behavior is to align to the middle.
  111. ALIGN        This parameter specifies the default horizontal justification of
  112.              all cells in this row.
  113. BGCOLOR      All cells in the row lose their table-default color and are filled
  114.              with the specified color.
  115.  
  116. Keep in mind that using a BGCOLOR parameter in the <TR> tag only affects the row you're defining; the rest of the rows in the table will still be either transparent or have the color you specified in the <TABLE> tag.
  117.  
  118.  
  119.  
  120.  
  121. Adding the Cells
  122.  
  123. <TD [WIDTH="num" HEIGHT="num" VALIGN="TOP|MIDDLE|BOTTOM" ALIGN="LEFT|CENTER|RIGHT" BGCOLOR="color"]>
  124.   :
  125. </TD>
  126.  
  127. The <TD> tag is used to specify the contents of one cell within a row.  All of the parameters have the same meanings as were specified previously, except for the fact that they now apply only to the particular cell being defined by the <TD> tag.
  128.  
  129.  
  130.  
  131.  
  132. Bringing it All Together
  133.  
  134. Consider the following HTML code:
  135.  
  136. <TABLE BORDER="1">
  137.     <TR>
  138.         <TD>
  139.             Row 1, Column 1
  140.         </TD>
  141.         <TD>
  142.             Row 1, Column 2
  143.         </TD>
  144.         <TD>
  145.             Row 1, Column 3
  146.         </TD>
  147.     </TR>
  148.     <TR>
  149.         <TD>
  150.             Row 2, Column 1
  151.         </TD>
  152.         <TD>
  153.             Row 2, Column 2
  154.         </TD>
  155.     </TR>
  156. </TABLE>
  157.  
  158. This is a very general starting point for creating a table. You can see that the definition begins with the <TABLE> tag. Next, the <TR> tag specifies that a row follows. Finally, there are three columns created using the <TD> tag. Follow the flow of the tags in the above snippet of code. The use of tags and their corresponding end-tags is much like a stack of papers ‚Äî papers are added and removed from the top of the stack. Always be certain that your tags balance properly. If you successfully typed in the code above, your table should look something like this:
  159.  
  160.  
  161.  
  162.  
  163.  
  164. Did it work for you? Wonderful! You've taken your first step to creating beautiful page layouts in HTML. The next step in your journey is to begin adding a little color to the table.
  165.  
  166.  
  167.  
  168.  
  169. Spice it up with Color!
  170.  
  171. Let's admit it, color always adds impact to any computer document, whether it be a spreadsheet or an HTML document. The key is to come up with colors that work well together. Take the following table, for instance:
  172.  
  173.  
  174.  
  175. BGCOLOR=       #FF0000         #FFFF00         #0000FF
  176.  
  177. This table illustrates a poor choice of colors. Not only are the colors too bright (well, my retinas are burning a little at the moment, anyway), but they do not compliment each other. Typically, shades of grey are used in graphical displays because they've been found to be pleasing and easy on the eyes (just look at the Mac OS... greyscale coloration is everywhere!) So instead, we could set up the same table with grey:
  178.  
  179.  
  180.  
  181. BGCOLOR=       #BBBBBB         #DDDDDD         #DDDDDD
  182.  
  183. Thus, we have a coloration scheme which not only is pleasing (and painless) to the eye, but adds a little something extra to the table. More often than not, it's best to stick to using changes in the shade of a single color within a table. For example, if you're Irish and decide to create a page which reflects your heritage, you may want to substitute a nice emerald green for the grey:
  184.  
  185.  
  186.  
  187. BGCOLOR=       #009000         #00D000         #00D000
  188.  
  189. This color scheme is a pleasing mixture of two shades of green:
  190.  
  191. <TABLE BORDER="1">
  192.     <TR>
  193.         <TD BGCOLOR="#009000">
  194.             Row 1, Column 1
  195.         </TD>
  196.         <TD BGCOLOR="#00D000">
  197.             Row 1, Column 2
  198.         </TD>
  199.         <TD BGCOLOR="#00D000">
  200.             Row 1, Column 3
  201.         </TD>
  202.     </TR>
  203. </TABLE>
  204.  
  205.  
  206.  
  207.  
  208. Looking Ahead
  209.  
  210. That's it. You now have the basic tools you need to create tables within your HTML documents. Next month we will begin construction of a page which will contain a list of files in tabular form. We will attempt to mimic the look of the Mac OS 8 Finder list view by utilizing our knowledge of color in HTML tables. Don't forget a hardhat!
  211.  
  212.  
  213.  
  214.  
  215. Code Exercise
  216.  
  217. Create a table which displays a 16 x 16 pixel image (same size as small icons in the Finder) with a program name, file size, creation date, and type of file to the right of the image. Hint: You need to create a table with four columns ‚Äî one for the graphic and file name, one for creation date, one for the file size, and one for the file type:
  218.  
  219.  
  220.  
  221.  
  222.  
  223. For an extra challenge, add the small triangle which appears to the left of a folder. The code in the next section demonstrates one possibility... don't peek before you try it, though!
  224.  
  225.  
  226.  
  227.  
  228. Code Exercise Solution
  229.  
  230. <TABLE CELLPADDING="1" CELLSPACING="1" BGCOLOR="#EFEFEF" BORDER="0">
  231.     <TR VALIGN="TOP">
  232.         <TD ALIGN="LEFT" BGCOLOR="#DEDFDF">
  233.             <IMG SRC="triangle.gif" ALIGN="LEFT">
  234.             <IMG SRC="pic1.gif" ALIGN="LEFT">
  235.             Folder Number One
  236.         </TD>
  237.         <TD ALIGN="LEFT">
  238.             Mon, Feb 16, 1998, 12:00 AM
  239.         </TD>
  240.         <TD ALIGN="CENTER">
  241.             118K
  242.         </TD>
  243.         <TD ALIGN="CENTER">
  244.             -
  245.         </TD>
  246.     </TR>
  247.     <TR VALIGN="TOP">
  248.         <TD ALIGN="LEFT" BGCOLOR="#DEDFDF">
  249.             <IMG SRC="blank.gif" ALIGN="LEFT">
  250.             <IMG SRC="pic2.gif" ALIGN="LEFT">
  251.             March Column
  252.         </TD>
  253.         <TD ALIGN="LEFT">
  254.             Sat, Feb 14, 1998, 11:00 AM
  255.         </TD>
  256.         <TD ALIGN="CENTER">
  257.             28K
  258.         </TD>
  259.         <TD ALIGN="CENTER">
  260.             DOCMaker File
  261.         </TD>
  262.     </TR>
  263. </TABLE>
  264.  
  265.  
  266. ¬†       Jeff Frey
  267.           jeff@applewizards.net
  268.  
  269.  
  270.    
  271.  
  272.  
  273.                                               http://applewizards.net/
  274.